//
//  APPLETabBar.swift
//  123
//
//  Created by pangjiaxing on 15/12/27.
//  Copyright © 2015年 pangjiaxing. All rights reserved.
//

import UIKit

class APPLETabBar: UITabBar {
  
    private lazy var plusbutton:UIButton={
        
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        button.sizeToFit()
        button.addTarget(self , action: "didClickPlusButton", forControlEvents: UIControlEvents.TouchUpInside)
        return button
        
    }()
    
    
    var plusButtonBag:(()->())?
    
    @objc private func didClickPlusButton(){
        plusButtonBag?()
    }
    
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        addSubview(plusbutton)
        backgroundImage=UIImage(named:"tabbar_background")
        
    }

    required init?(coder aDecoder: NSCoder) {
        
        fatalError()
        
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        plusbutton.center.x = mainScreenW*0.5
        plusbutton.center.y = bounds.height*0.5
        
        var index=0
        
        for  systemButton in subviews{
            if systemButton.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                systemButton.frame.size.width = bounds.width*0.2
                
                systemButton.frame.origin.x = CGFloat(index)*bounds.size.width*0.2
                
                index++
                if(index==2)
                {
                    index++
                }
                
            }
            
        }
    }
}
